package com.anxin.act.busFlow.service;

import java.util.List;
import com.anxin.framework.web.service.BaseService;
import com.anxin.common.utils.SecurityUtils;
import com.anxin.sys.system.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.anxin.act.busFlow.dao.WfConfigFlowDao;
import com.anxin.act.busFlow.entity.WfConfigFlow;

/**
 * 业务流程配置Service业务层处理
 *
 * @author jbs
 * @date 2020-04-08
 */
@Service
public class WfConfigFlowService extends BaseService<WfConfigFlowDao,WfConfigFlow>{
    @Autowired
    private WfConfigFlowDao wfConfigFlowDao;

    /**
     * 查询业务流程配置
     *
     * @param id 业务流程配置ID
     * @return 业务流程配置
     */
    public WfConfigFlow getById(String id){
        WfConfigFlow wfConfigFlow = new WfConfigFlow();
        if(id != null){
            wfConfigFlow = wfConfigFlowDao.getById(id);
        }
        return wfConfigFlow;
    }

    /**
     * 查询业务流程配置列表
     *
     * @param wfConfigFlow 业务流程配置
     * @return 业务流程配置
     */
    public List<WfConfigFlow> findList(WfConfigFlow wfConfigFlow){
        return wfConfigFlowDao.findList(wfConfigFlow);
    }

    /**
     * 流程流程配置
     * @param wfConfigFlow
     * @return
     */
    public int save(WfConfigFlow wfConfigFlow){
        int saveCount = super.save(wfConfigFlow);
        return saveCount;
    }

    /**
     * check wfconfigFlow同样的配置是否存在
     * @param wfConfigFlow
     * @return
     */
    public boolean checkWfConfigFlow(WfConfigFlow wfConfigFlow){
        int count = wfConfigFlowDao.checkWfConfigFlow(wfConfigFlow);
        return count == 0;
    }

    /**
     * 保存业务流程配置
     *
     * @param wfConfigFlow 业务流程配置
     * @return 结果
     */
    public int update(WfConfigFlow wfConfigFlow){
        return super.save(wfConfigFlow);
    }


    /**
     * 删除业务流程配置信息
     *
     * @param id 业务流程配置ID
     * @return 结果
     */
    public int deleteById(String id){
        SysUser user = SecurityUtils.getUser();
        if(user == null){
            return 0;
        }
        return wfConfigFlowDao.deleteById(id,user.getId());
    }
}
